@extends('layouts.default') @section('main')
<link rel="stylesheet" href="/css/uniform.css" />
<link rel="stylesheet" href="/css/select2.css" />
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i
				class="icon-home"></i> 首页</a> <a href="#" class="current">活动管理</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				@if(in_array('project_add',$actions)) 

                        <table>
                            <tr>
                                <th>
                                    <label >项目名称 :</label>
                                </th>
                                <th>
                                    <div class="controls">
                                        <input type="text"  name="project_name" placeholder="项目名称，按下enter键搜索" />
                                    </div>
                                </th>

                                <th>
                                    <label >项目 :</label>
                                </th>
                                <th>
                                    <div class="controls">
                                        <select name="project_id" id="project">
                                            <option value="0">请选择</option>
                                        </select>
                                    </div>
                                </th>

                                <th id="roadShow" style="display: none;">
                                    <label >路演申请编号 :</label>
                                </th>
                                <th id="roadShowId" style="display: none;">
                                    <div class="controls">
                                        <select name="show_id" id="show_id">
                                            <option value="0">请选择</option>
                                        </select>
                                    </div>
                                </th>

                                <th>
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                    <div class="controls">
                                        <button class="btn project_add">新增</button>
                                    </div>
                                </th>
                            </tr>
                        </table>



				@endif
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"><i class="icon-th"></i></span>
						<h5>活动管理</h5>
					</div>
					<div class="widget-content nopadding">
						<table class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>活动名称</th>
									<th>项目名称</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								@foreach($datas as $key => $data)
								<tr class="gradeX">
									<td>{{$data->a_subject}}</td>
									<td>{{$data->p_subject}}</td>
									<td class="center">
										@if(in_array('project_delete',$actions)) <a data-original-title="删除"
										data-toggle="modal" class="tip activity_project_delete"
										activity_project_id="{{$data->id}}" href="#myAlert"><i
											class="icon-remove"></i></a> @endif
									</td>
								</tr>
								@endforeach
							</tbody>
						</table>
					</div>
				</div><?php echo $datas->render();?>
      </div>
		</div>
	</div>
</div>
<div>
	<div id="myAlert" class="modal hide">
		<div class="modal-header">
			<button data-dismiss="modal" class="close" type="button">×</button>
			<h3>提示</h3>
		</div>
		<div class="modal-body">
			<p>确认删除这条数据吗？</p>
		</div>
		<div class="modal-footer">
			<a data-dismiss="modal" class="btn btn-primary" href="javascript:void(0);">确定</a>
			<a data-dismiss="modal" class="btn" href="javascript:void(0);">取消</a>
		</div>
	</div>
	<form action="{{url('activity/projectdelete')}}" method="post"
		id="activityForm">
		<input type="hidden" name="apid" value="0">
	</form>
	<input type="hidden" name="activity_id" value="{{$aid}}">
</div>
<script src="/js/jquery.min.js"></script>
<script src="/js/matrix.tables.js"></script>
<script src="/js/common.js"></script>
<script>

$("input[name='project_name']").keydown(function(event) {
        if (event.which == "13") {
            var project_name = $("input[name='project_name']").val();
            if (project_name == '') {
                alert('项目名称不能为空');
                return;
            }
            ajaxRequest({"project_name": project_name}, "{{url('activity/projects')}}", function (data) {
                if (data.status) {
                    var html = '<option value="">请选择</option>';
                    $.each(data.message, function (i, n) {
                        html += "<option value='" + n.id + "'>" + n.subject + "</option>";
                    });
                    $("#project").html(html);
                } else {
                    alert(data.message);
                }
            });
        }
    });


$("select[name=project_id]").change(function(){
    var project_id = $(this).val();
    ajaxRequest({"project_id":project_id},"{{url('activity/road-show')}}",function(data){
        if(data.status){
            var html = '<option value="">请选择</option>';

            $.each(data.message, function (i, n) {
                html += "<option value='" + n.roadshow_apply_id + "'>路演申请编号" + n.roadshow_apply_id + "</option>";
            });

            $("#show_id").html(html);
            $("#roadShow").removeAttr("style");
            $("#roadShowId").removeAttr("style");

            var roadshow = '<input type="hidden" name="roadshow" value="true">';
            $("input[name='_token']").after(roadshow);

        }else{
            $("#roadShow").attr("style",'display: none;');
            $("#roadShowId").attr("style",'display: none;');
            $("input[name='roadshow']").attr("value",'false');
        }
    });

})



$(".project_add").click(function(event){
    if (event.which == "13") {
        return false;
    }
	var project_id = $("#project").val();
	var activity_id = $("input[name='activity_id']").val();
	var show_id = $("select[name='show_id']").val();
	var show = $("input[name='roadshow']").val();
	if(activity_id == 0){
		alert('参数异常');
		return;
	}
	if(project_id == 0){
		alert('请选择项目');
		return;
	}
	ajaxRequest({"activity_id":activity_id,"project_id":project_id,"show_id":show_id,"show":show},"{{url('activity/projectinsert')}}",function(data){
		if(data.status){
			window.location.reload();
		}else{
			alert(data.message);
		}
	});
});



$(".activity_project_delete").click(function(){
	var activity_project_id = $(this).attr("activity_project_id");
	$("input[name='apid']").val(activity_project_id);
});
$(".btn-primary").click(function(){
	var activity_project_id = $("input[name='apid']").val();
	if(activity_project_id == 0){
		alert('参数异常');
		return;
	}
	ajaxRequest($('#activityForm').serializeArray(),$('#activityForm').attr('action'),function(data){
		if(data.status){
			window.location.reload();
		}else{
			alert(data.message);
		}
	});
});
</script>
@stop
